package editor;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

//This is the main program that implements source code highlighting
public class Color extends JFrame {
    public RSyntaxTextArea textArea;
    public RTextScrollPane rtext;
    public JPanel cp;

    public void TextEditorDemo(File file) throws IOException {

        FileInputStream in = new FileInputStream(file);
        byte[] byt = new byte[1024];
        int len = in.read(byt);

        cp = new JPanel(new BorderLayout());

        textArea = new RSyntaxTextArea(40, 100);
        textArea.setText(new String(byt, 0, len));
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);

        textArea.setCodeFoldingEnabled(true);

        rtext = new RTextScrollPane(textArea);

        cp.add(rtext);

        setContentPane(cp);

        setTitle("Text Editor Demo");

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        pack();

        setLocationRelativeTo(null);

    }

    public RTextScrollPane getrtext(){
        return rtext;
    }


//    public static void main(String[] args) {
////// Start all Swing applications on the EDT.
//
//        SwingUtilities.invokeLater(() -> {
//            Color color = new Color();
//            try {
//                color.TextEditorDemo(new File("C:/Users/DELL/Desktop/leapYear.java"));
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//            color.setVisible(true);
//
//
//        });
//
//    }
}
//
//}
